$(document).ready(function () {
	request = haoutil.system.getRequest();
	if (window.top) {//有父级
	    request = $.extend(request, haoutil.system.getRequest(window.top));
	}
	initMap();
});
let request;
function initMap() {
	map2D3D.viewTo23D(); //默认分屏

	haoutil.loading.show();
	$.ajax({
		type: "get",
		contentType: "application/json; charset=utf-8",
		dataType: "json",
		url: "config/map2d3d.json",
		success: function (config) {
			map2D3D.createMap2D('map', config.map);
			map2D3D.createMap3D('cesiumContainer', config.map3d);

			haoutil.loading.hide();
			initWork();
		},
		error: function (XMLHttpRequest, textStatus, errorThrown) {
			haoutil.loading.hide();
			haoutil.alert("Json文件" + opt.url + "加载失败！");
		}
	});
}
function initWidget() {
	let viewer = map2D3D.viewer;
    haoutil.loading.show();

    $.ajax({
        type: "get",
        dataType: "json",
        url: "config/widget.json",
        timeout: 0,
        success: function (widgetCfg) {
            haoutil.loading.hide();

            //url如果有传参时的处理
            if (haoutil.isutil.isNotNull(request.widget)) {
                if (request.onlyStart) widgetCfg.widgetsAtStart = [];
                widgetCfg.widgetsAtStart.push({
                    uri: request.widget,
                    name: request.name || "",
                    windowOptions: {
                        closeBtn: !request.onlyStart,
                    },
                    request: request
                });
                viewer.mars.centerAtHome({ duration: 0 });
            }

            //初始化widget管理器
            mars3d.widget.init(viewer, widgetCfg); //tip: 此方法有第3个参数支持定义父目录。

            // if (lastWidgetItem) {
            //     activateWidget(lastWidgetItem);
            //     lastWidgetItem = null;
            // }
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            haoutil.loading.hide();
            haoutil.alert("config/widget.json文件加载失败！");
        }
    });
}